#include <iostream>
#include <string>
using namespace std;
int t, n, k;
string s;
int fun()
{
	int ret = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'L')
		{
			ret--;
		}
		else
		{
			if (i - 1 >= 0 && i - 2 >= 0 && s[i - 1] == 'W' && s[i - 2] == 'W')
			{
				ret += k;
			}
			else
			{
				ret += 1;
			}
		}
	}
	return ret;
}
int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n >> k >> s;
		cout << fun() << endl;
	}

	return 0;
}